<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<html>
	<title>管理员-${_systemName}</title>
	<jsp:include page="../common/top.jsp"></jsp:include>
	<body class="page-content">
		<div class="page-header">
			<h1>
				分配角色
			</h1>
		</div>
		<div class="page-content-area">
		<div class="row">
		<div class="col-xs-12">
				<!-- PAGE CONTENT BEGINS -->
				<form id="_editForm" class="form-horizontal" role="form" 
					validate="true">
					<input id="_userId" type="hidden" name="userId" value="${userId}">
					<input id="_roleIds" type="hidden" name="roleIds">
					
					<div class="form-group">
						<label for="_appId" class="col-sm-3 control-label no-padding-right">应用</label>
		
						<div class="col-sm-3">
							<select  class="form-control help-validate" disabled="disabled">
								<option >${_systemName}</option>
							</select>
						</div>
					</div>
					
					<div class="form-group">
						<div class="col-xs-12 col-sm-9">
							<div id="_roleDiv" class="clearfix help-validate">
								<c:forEach var="item" items="${roleList}">
									<div class='col-sm-2'>
										<label>
											<input name="roleId" value="${item.id}" type="checkbox" class="ace" ${item.isChecked ? 'checked="checked"' : ''}/>
											<span class="lbl">&nbsp;&nbsp;${item.name}</span>
										</label>
									</div>
								</c:forEach>
							</div>
						</div>
					</div>
					
					<div class="clearfix form-actions">
						<div class="col-md-offset-3 col-md-9">
							<button id="_submit" type="button" class="btn btn-info" data-loading-text="正在提交...">
								<i class="ace-icon fa fa-check bigger-110"></i>
								提交
							</button>
		
							&nbsp; &nbsp; &nbsp;
							<button id="_cancle" class="btn" type="reset">
								<i class="ace-icon fa  fa-times bigger-110"></i>
								取消
							</button>
						</div>
					</div>
				</form>
		
			</div>
		</div>
		
		
		</div>
		<!--[if lte IE 8]>
		  <script src="${_staticPath}/assets/js/excanvas.js"></script>
		<![endif]-->
		<jsp:include page="../common/bottom.jsp"></jsp:include>
		<script type="text/javascript">
			var scripts = [null,
				// UI
				"${_staticPath}/assets/js/jquery-ui.custom.js?v=" + Math.random(),
				// Form提交Json转换
				"${_staticPath}/script/jquery.form.min.js?v=" + Math.random(),
				// 验证
				"${_staticPath}/script/jquery.validate-2.0.min.js?v=" + Math.random(),
				// 验证定制
				"${_staticPath}/script/jquery.validate-2.0.custom.min.js?v=" + Math.random(),
				null];
			$('.page-content-area').ace_ajax('loadScripts', scripts, function() {
				jQuery(function($) {
					
					// 提交
					$("#_submit").click(function(){
						if($('#_editForm').validate()){
							var roleIds = "";
							$("input[name='roleId']:checked").each(function(i, d){
								if(i > 0){
									roleIds += ",";
								}
								roleIds += $(this).val();
							});
							$("#_roleIds").val(roleIds);
							
							var btn = $(this);
							btn.button('loading');
							$.post("${path}/admin/manager/allocateSave", $.formJson('_editForm'),function(d) {
								if(d){
									btn.button('reset');
									if(d.status == '0000'){
										window.location.href = "${path}/admin/manager";
									}
									else {
										location.reload();
									}
								}
					        },'json');
						}
					});
					
					// 取消
					$("#_cancle").click(function(){
						window.location.href = "${_path}/admin/manager";
					});
				});
			});
		</script>
		
	</body>
</html>




